package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * 获取Person类中的所有方法, 判断若方法被@AutoRunMethod标记则调用方法, 否则提示
 */
public class Test3 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class);
        Object obj = c.newInstance("张三");

        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods) {
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark) {
                System.out.println("调用方法:" + method.getName() + "()");
                method.invoke(obj);
            } else {
                System.out.println(method.getName() + "()没有被标记");
            }
        }
    }
}
